package main

import (
    "facecat"
    "io/ioutil"
)

/*
* 重绘背景的实现方法
* view:视图
* paint:绘图对象
* clipRect:裁剪区域
*/
func OnPaint(view *facecat.FCView, paint *facecat.FCPaint, clipRect facecat.FCRect) {
    facecat.OnPaintDefault(view, paint, clipRect)
}

/*
* 重绘边框的实现方法
* view:视图
* paint:绘图对象
* clipRect:裁剪区域
*/
func OnPaintBorder(view *facecat.FCView, paint *facecat.FCPaint, clipRect facecat.FCRect) {
    facecat.OnPaintBorderDefault(view, paint, clipRect)
}

/*
*视图的鼠标移动方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseMove(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
    facecat.OnMouseMoveDefault(view, mp, buttons, clicks, delta)
}

/*
*视图的鼠标按下方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseDown(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
	facecat.OnMouseDownDefault(view, mp, buttons, clicks, delta)
}

/*
*视图的鼠标抬起方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseUp(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
    facecat.OnMouseUpDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标点击实现方法
* view: 图层
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
* clicks:点击次数
*/
func OnClick(view *facecat.FCView, firstTouch bool, firstPoint facecat.FCPoint, secondTouch bool, secondPoint facecat.FCPoint, clicks int){
    facecat.OnClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)
}

/*
* 鼠标滚动实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseWheel(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标离开实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseLeave(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标进入实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseEnter(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 键盘按下
* view:视图
* key:按键
*/
func OnKeyDown(view *facecat.FCView, key int){

}

/*
* 键盘抬起
* view:视图
* key:按键
*/
func OnKeyUp(view *facecat.FCView, key int){
}

/*
* 更新悬浮状态
* views:视图集合
*/
func UpdateView(views []*facecat.FCView) {
    facecat.UpdateViewDefault(views)
}

var appPaint = new(facecat.FCPaint)

func WndProc(hwnd facecat.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
    return facecat.WndProcDefault(appPaint, hwnd, msg, wParam, lParam)
}

func main() {
    appPaint = facecat.CreatePaint()
    appPaint.OnPaint = OnPaint
    appPaint.OnPaintBorder = OnPaintBorder
    appPaint.OnMouseDown = OnMouseDown
    appPaint.OnMouseMove = OnMouseMove
    appPaint.OnMouseUp = OnMouseUp
    appPaint.OnMouseWheel = OnMouseWheel
    appPaint.OnClick = OnClick
    appPaint.OnUpdateView = UpdateView
    appPaint.OnMouseLeave = OnMouseLeave
    appPaint.OnMouseEnter = OnMouseEnter
    appPaint.OnKeyDown = OnKeyDown
    appPaint.OnKeyUp = OnKeyUp
    facecat.CreateMainWindow(appPaint, "FaceCat-Go", WndProc)
    xmlStr, _ := ioutil.ReadFile("xml//treeexample.xml")
    facecat.RenderFaceCat(appPaint, string(xmlStr))
    //获取第二页
    tree := facecat.FindViewByName("Tree", appPaint.Views)
    tree.GetTree().HeaderHeight = 0
    tree.GetTree().ShowCheckBox = true
    column := facecat.CreateTreeColumn()
    column.Width = 500
    tree.GetTree().Columns = append(tree.GetTree().Columns, column)
       
    rootNode := facecat.CreateTreeNode()
    rootNode.Value = "证监会行业类"
    noneNode := new(facecat.FCTreeNode)
    noneNode.IsNotEmpty = false
    facecat.AppendTreeNode(tree, rootNode, noneNode)

    node1 := facecat.CreateTreeNode()
    node1.Value = "农、林、牧、渔业"
    facecat.AppendTreeNode(tree, node1, rootNode)

    var strs1 []string
    strs1 = append(strs1, "农业")
    strs1 = append(strs1, "林业")
    strs1 = append(strs1, "畜牧业")
    strs1 = append(strs1, "渔业")
    strs1 = append(strs1, "农、林、牧、渔服务业")
    for i := 0; i < len(strs1); i++{
	    subNode1 := facecat.CreateTreeNode()
	    subNode1.Value = strs1[i]
	    facecat.AppendTreeNode(tree, subNode1, node1)
    }

    node2 := facecat.CreateTreeNode()
    node2.Value = "采矿业"
    facecat.AppendTreeNode(tree, node2, rootNode)

    var strs2 []string
    strs2 = append(strs2, "煤炭开采和洗选业")
    strs2 = append(strs2, "石油和天然气开采业")
    strs2 = append(strs2, "黑色金属矿采选业")
    strs2 = append(strs2, "有色金属矿采选业")
    strs2 = append(strs2, "非金属矿采选业")
    strs2 = append(strs2, "开采辅助活动")
    for i := 0; i < len(strs2); i++{
	    subNode2 := facecat.CreateTreeNode()
	    subNode2.Value = strs2[i]
	    facecat.AppendTreeNode(tree, subNode2, node2)
    }

    node3 := facecat.CreateTreeNode()
    node3.Value = "制造业"
    facecat.AppendTreeNode(tree, node3, rootNode)

    var strs3 []string
    strs3 = append(strs3, "农副食品加工业")
    strs3 = append(strs3, "食品制造业")
    strs3 = append(strs3, "酒、饮料和精制茶制造业")
    strs3 = append(strs3, "纺织业")
    strs3 = append(strs3, "纺织服装、服饰业")
    strs3 = append(strs3, "皮革、毛皮、羽毛及其制品和制鞋业")
    strs3 = append(strs3, "木材加工和木、竹、藤、棕、草制品业")
    strs3 = append(strs3, "家具制造业")
    strs3 = append(strs3, "造纸和纸制品业")
    strs3 = append(strs3, "印刷和记录媒介复制业")
    strs3 = append(strs3, "文教、工美、体育和娱乐用品制造业")
    strs3 = append(strs3, "石油加工、炼焦和核燃料加工业")
    strs3 = append(strs3, "化学原料及化学制品制造业")
    strs3 = append(strs3, "医药制造业")
    strs3 = append(strs3, "化学纤维制造业")
    strs3 = append(strs3, "橡胶和塑料制品业")
    strs3 = append(strs3, "非金属矿物制品业")
    strs3 = append(strs3, "黑色金属冶炼和压延加工业")
    strs3 = append(strs3, "有色金属冶炼和压延加工业")
    strs3 = append(strs3, "金属制品业")
    strs3 = append(strs3, "通用设备制造业")
    strs3 = append(strs3, "专用设备制造业")
    strs3 = append(strs3, "汽车制造业")
    strs3 = append(strs3, "铁路、船舶、航空航天和其他运输设备制造业")
    strs3 = append(strs3, "电气机械和器材制造业")
    strs3 = append(strs3, "计算机、通信和其他电子设备制造业")
    strs3 = append(strs3, "仪器仪表制造业")
    strs3 = append(strs3, "其他制造业")
    strs3 = append(strs3, "废弃资源综合利用业")
    for i := 0; i < len(strs3); i++{
	    subNode3 := facecat.CreateTreeNode()
	    subNode3.Value = strs3[i]
	    facecat.AppendTreeNode(tree, subNode3, node3)
    }
    facecat.Invalidate(appPaint)
    facecat.ShowWindow(appPaint)
}